<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/element.css" rel="stylesheet"/>
    <link href="../css/styleindex.css" rel="stylesheet"/>
    <link href="../css/swiper.min.css" rel="stylesheet"/>
    <style>
    .el-input__inner{
      border: 0;
      font-size: 1rem;
      text-align: center;
    }.el-input__prefix{
      display: none;
    }
    </style>
</head>
<body style="background:#EFF0F4;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <div class="x-header-g" id="header">
        <a class="x-header-arrow" @click="api.closeWin()"></a>
        <div class="x-header-t">调拨验收</div>
      </div>
      <div class="container">
        <!--  -->
        <div class="x-ico-month">
          <el-date-picker v-model="cardsmonth" type="date" placeholder="选择日" @change="getmonth" format="yyyy 年 MM 月dd 日" value-format="yyyyMMdd" :editable="notkey"></el-date-picker>
        </div>
        <!--  -->
  			<div class="x-train-tabs swiper-container">
  				<div class="swiper-wrapper">
  					<div class="swiper-slide x-train-items" v-for="(item,index) in tabsdata" :key="item.id" @click="changetab(index,item.id)" :class="{active:curId==index}">{{item.title}}</div>
  				</div>
  			</div>
        <div class="">
          <template>
            <el-table :data="tabledata" @cell-click="gotrainpro">
              <el-table-column label="验收人" width="90" fixed>
                <template slot-scope="scope">
                  {{scope.row.save_username}}
                </template>
              </el-table-column>
              <el-table-column label="总金额" width="">
                <template slot-scope="scope">
                  {{scope.row.total_price}}
                </template>
              </el-table-column>
              <el-table-column label="验收时间" width="">
                <template slot-scope="scope">
                  {{scope.row.time}}
                </template>
              </el-table-column>
              <el-table-column label="操作" width="">
                <template slot-scope="scope">
                  <el-button type="text">查看</el-button>
                </template>
              </el-table-column>
            </el-table>
          </template>
        </div>
        <!--  -->
        <div class="x-pro-gobtn" @click="isok" v-if="issave==0">调拨验收</div>
        <div class="x-pro-gobtn x-disabled" v-if="issave==1">无待验收</div>
		  </div>
      <!-- <div class="x-nothing" v-show="noshow">暂无权限</div> -->
    </div>
  </div>

  <script type="text/javascript" src="../script/vue.js"></script>
  <script type="text/javascript" src="../script/element.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/base.js"></script>
  <script type="text/javascript" src="../script/jquery-1.11.1.min.js"></script>
  <script type="text/javascript" src="../script/swiper.min.js"></script>
	<script>
apiready = function () {
    $api.fixStatusBar($api.byId('header'));
    api.addEventListener({
        name: 'allotchecksucc'
    }, function(ret, err) {
      vm.gettrainadmin()
      vm.getsavedata()
    });

    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          tabsdata:'',
          curId:0,
          tabledata:[],
          cardsmonth:'',
          cardsmonthtoy:'',
          cardsmonthtom:'',
          tabsid:0,
          notkey:false,
          isfromindex:true,
          noget:0,
          askname:'',
          yesshow:false,
          noshow:false,
          allmoney:0,
          issave:-1,
          fordata:{},
          isclick:true,
        }
      },
      created:function() {
        var that=this;


      },
      mounted:function(){
        var that=this;
        //当前月份
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth()+1;
        var day = date.getDate();
        if(month<10){
          month = '' + 0 + month;
        }
        if(day<10){
          day = '' + 0 + day;
        }
        var toMonth = '' + year + month + day;
        that.cardsmonth = toMonth;
        that.cardsmonthtoy = year;
        that.cardsmonthtom = month;
        that.getswiper()
      },
      methods: {
        //提交
        isok:function(){
          var that = this;
          api.openWin({
              name: 'allotcheck',
              url: './allotcheck.html',
              pageParam: {
                  supplierid:that.tabsid,
                  fordata:that.fordata,
                  time:that.cardsmonth
              }
          });
        },
        //切换选择日期
        getmonth:function(val){
          var that = this;
          that.cardsmonth = val;
          that.gettrainadmin()
          that.getsavedata()

        },
        //点击列
        gotrainpro:function(val){
          api.openWin({
              name: 'allotcheckinfo',
              url: './allotcheckinfo.html',
              pageParam: {
                  id: val.id
              }
          });
        },
        //切换选项卡 表格数据
        changetab:function(index,id){
          var that = this;
          that.curId = index;
          that.tabsid = id;
          that.gettrainadmin()
          that.getsavedata()
        },
        //swiper
        getswiper:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/material/wsList',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                type:'3'
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){

                  if(ret.data.length==0){
                    that.noshow = true;
                    that.yesshow = false;
                  }else{
                    that.yesshow = true;
                    that.noshow = false;
                    that.tabsdata = ret.data;
                    that.tabsid = ret.data[0].id;
                    that.gettrainadmin()
                    that.getsavedata()
                  }
                  that.$nextTick(function(){
                    var mySwiper = new Swiper('.swiper-container',{
                      freeMode: true,
                      loop:false,//设置 active slide 居中后，会有左右留白现象，添加此会让未尾的导航补齐前后空白
                      slideToClickedSlide: true,//设置为true则点击slide会过渡到这个slide。
                      slidesPerView: 3.5,
                      centeredSlides: false,//设定为true时，active slide会居中，而不是默认状态下的居左。
                      spaceBetween: 10,//slide之间设置距离
                      slidesOffsetBefore: 0,//设定slide与左边框的预设偏移量
                      slidesOffsetAfter: 0,//设定slide与右边框的预设偏移量

                    });

                  });
              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.ms,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //表格data
        gettrainadmin:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/material/allotList',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                wsid:that.tabsid,
                date:that.cardsmonth
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){

                  that.tabledata = ret.data.list;
                  that.noget = ret.data.is_save;
                  if(that.noget>='1'){//已验收
                    that.allmoney = 0;
                    for(var i=0;i<that.tabledata.length;i++){
                      that.allmoney += that.tabledata[i].total_price
                    }
                  }else if(that.tabledata.length==0){//未验收 空
                    that.noget = 3;
                  }
                  that.askname = ret.data.save_username;

              }else if(ret.status == 0){
                that.tabledata = [];
                that.noget = 3;
                that.askname = '';
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //
        getsavedata:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/material/allotView',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                wsid:that.tabsid,
                date:that.cardsmonth
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){//供货验收
                that.issave = 0;
                that.fordata = ret.data;

              }else if(ret.status == 0){//无待验收
                that.issave = 1;
              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
      }
    })
	}

	</script>
</body>
</html>
